<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>key是字符串</title>
</head>
<body>
    <script>
        //key是字符串
        var myMap = new Map();
        var keyString = "a string";
        
        myMap.set(keyString, "和键'a string'关联的值");
        myMap.get(keyString);  //“和键 'a string' 关联的值“
        myMap.get("a string"); //"和键'a string 关联的值"
                                //因为keyString==='a string'
    </script>

    <script>
        //key是对象
        var myMap = new Map();
        var keyObj = {};
        
        myMap.set(keyObj, "和键 keyObj关联的值");
        myMap.get(keyObj);  //“和键 keyObj 关联的值“
        myMap.get({}); // undefined,因为keyObj !=={}
    </script>

    <script>
        //key是函数
        var myMap = new Map();
        var keyFunc = function () {};// 函数
 
        myMap.set(keyFunc, "和键 keyFunc 关联的值");
 
        myMap.get(keyFunc); // "和键 keyFunc 关联的值"
        myMap.get(function() {}) // undefined, 因为 keyFunc !== function () {}
    </script>

    <script>
        //key是NaN
        var myMap = new Map();
        myMap.set(NaN, "not a number");
 
        myMap.get(NaN); // "not a number"
 
        var otherNaN = Number("foo");
        myMap.get(otherNaN); // "not a number"
        //虽然NaN和任何值甚至和自己都不相等，NaN作为Map的键来说是没有区别的
    </script>
</body>
</html>